use super::Argument;

pub struct Request<'a> {
    method_id: u64,
    arguments: Vec<Argument<'a>>,
}

impl<'a> Request<'a> {
    pub fn new(method_id: u64) -> Self {
        Self {
            method_id,
            arguments: vec![],
        }
    }

    pub fn with_arg(method_id: u64, arg: Argument<'a>) -> Self {
        Self {
            method_id,
            arguments: vec![arg],
        }
    }

    pub fn with_args<I: IntoIterator<Item = Argument<'a>>>(method_id: u64, args: I) -> Self {
        Self {
            method_id,
            arguments: Vec::from_iter(args),
        }
    }

    pub fn method_id(&self) -> u64 {
        self.method_id
    }

    pub fn argc(&self) -> usize {
        self.arguments.len()
    }

    pub fn argv(&self, index: usize) -> Option<&Argument<'_>> {
        self.arguments.get(index)
    }

    pub fn args(&self) -> &[Argument<'_>] {
        &self.arguments
    }

    /// 添加参数
    pub fn add_argument(&mut self, arg: Argument<'a>) {
        self.arguments.push(arg);
    }

    /// 获取参数列表（兼容recorder模块）
    pub fn arguments(&self) -> &[Argument<'_>] {
        &self.arguments
    }

    pub fn into_inner(self) -> Vec<Argument<'a>> {
        self.arguments
    }
}

#[repr(C)]
struct RequestLayout<'a> {
    method_id: u64,
    arg_count: usize,
    arg_ptr: *const Argument<'a>,
}

impl<'a> RequestLayout<'a> {
    pub fn from_request(request: Request<'a>) {

    }

    pub fn into_request(self) -> Request<'a> {
        todo!()
    }
}